home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / rng.exe / RANDOM-C.DOC < prev    next >
Text File  |  1990-05-28  |  4KB  |  85 lines

  1.                  Notes on the C Language Version
  2.  
  3. The C code was derived from PD1:<MSDOS.FORTRAN>RANDOM.ARC, and has
  4. been linted with PC-Lint version 4.00a and tested using Microsoft C
  5. version 5.10.  In doing the translation, I tried to change as little
  6. as possible; in fact, all of the variable names and function
  7. (subroutine) names are the same in the C and FORTRAN versions.  Some
  8. of the comment blocks from the FORTRAN version were copied verbatim
  9. into the C version.
  10.  
  11. The C language version as distributed will compile and execute as a
  12. stand-alone program, allowing you to verify that the random number
  13. generator is working correctly with your compiler (if your compiler
  14. does not support full ANSI function prototypes, minor changes may be
  15. required).  When executed, the program should display the following
  16. (after a delay of several seconds or more):
  17.  
  18.   6533892.0  14220222.0   7275067.0   6172232.0   8354498.0  10633180.0
  19.  
  20. Use function main() as an example of how to call the random number
  21. generator from your program.
  22.  
  23. The remainder of this file was copied from RANDOM.DOC from
  24. PD1:<MSDOS.FORTRAN>RANDOM.ARC.  Thanks to David LaSalle for posting it.
  25.  
  26.      Jim Butler
  27.      Ithaca College
  28.      BUTLER%ITHACA.BITNET@CORNELLC.CIT.CORNELL.EDU
  29. -------------------------------------------------------------------------
  30. Date: Tue, 28 Feb 89 10:29:08 PST
  31. From: MINUIT%FSU.MFENET@NMFECC.ARPA
  32. Subject: á random number generators
  33.  
  34. When I posted the code for George Marsaglia's universal random number 
  35. generator, I forgot to mention that the seed variables can only have 
  36. certain values:
  37.  
  38. i, j, and k  must be between 1 and 178 (not all of them 1)
  39. l must be in the range 0 to 168
  40.  
  41. I am posting a slightly modified version of the code that requires only two
  42. seed variables which basically have the range 0 to 30000. One nice feature 
  43. of this version is that each subsequence of numbers specified by the two 
  44. seeds has a length of approximately 10^30. If different parts of a large 
  45. calculation is being worked on by several people, each person could be 
  46. given his own IJ seed. That would leave 30000 more seeds for the individual 
  47. to use -- without fear that any part of the overall calculation would 
  48. experience correlations in the random numbers. 
  49.  
  50. Finally, it should also be noted that to save the state of the random number 
  51. generator at any point in time, you have to save the entire contents of the
  52. common block
  53.  
  54. - David LaSalle
  55. minuit%fsu@nmfecc.arpa
  56.  
  57. SCRI
  58. Florida State University
  59. Tallahassee, FL 32306-4052
  60. (904)644-1010
  61. -------------------------------------------------------------------------
  62. C This random number generator originally appeared in "Toward a Universal 
  63. C Random Number Generator" by George Marsaglia and Arif Zaman. 
  64. C Florida State University Report: FSU-SCRI-87-50 (1987)
  65. C It was later modified by F. James and published in "A Review of Pseudo-
  66. C random Number Generators" 
  67. C THIS IS THE BEST KNOWN RANDOM NUMBER GENERATOR AVAILABLE.
  68. C       (However, a newly discovered technique can yield 
  69. C         a period of 10^600. But that is still in the development stage.)
  70. C
  71. C It passes ALL of the tests for random number generators and has a period 
  72. C   of 2^144, is completely portable (gives bit identical results on all 
  73. C   machines with at least 24-bit mantissas in the floating point 
  74. C   representation). 
  75. C The algorithm is a combination of a Fibonacci sequence (with lags of 97
  76. C   and 33, and operation "subtraction plus one, modulo one") and an 
  77. C   "arithmetic sequence" (using subtraction).
  78. C
  79. C On a Vax 11/780, this random number generator can produce a number in 
  80. C    13 microseconds (FORTRAN version - JB). 
  81. C======================================================================== 
  82.